Socket
Socket
Sign inDemoInstall

@smithy/util-waiter

Package Overview
Dependencies
Maintainers
2
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@smithy/util-waiter

Shared utilities for client waiters for the AWS SDK


Version published
Weekly downloads
8.5M
decreased by-4.16%
Maintainers
2
Weekly downloads
 
Created

What is @smithy/util-waiter?

@smithy/util-waiter is a utility package designed to help with implementing waiters in JavaScript applications. Waiters are used to poll for a resource to reach a desired state, which is particularly useful in scenarios involving asynchronous operations or state transitions.

What are @smithy/util-waiter's main functionalities?

Waiter Configuration

This feature allows you to configure a waiter with specific parameters such as minimum and maximum delay. The `createWaiter` function is used to create a waiter that will poll the `checkState` function until the desired state is reached.

const { createWaiter, WaiterState } = require('@smithy/util-waiter');

const waiterConfig = {
  minDelay: 2,
  maxDelay: 120,
};

const checkState = async () => {
  // Logic to check the state of the resource
  return { state: WaiterState.SUCCESS };
};

const waiter = createWaiter(waiterConfig, checkState);

waiter().then(() => console.log('Resource reached the desired state.')).catch((err) => console.error('Failed to reach the desired state:', err));

Custom Retry Logic

This feature allows you to implement custom retry logic by specifying a `retryStrategy` function in the waiter configuration. The `retryStrategy` function determines the delay between retries based on the number of attempts.

const { createWaiter, WaiterState } = require('@smithy/util-waiter');

const waiterConfig = {
  minDelay: 2,
  maxDelay: 120,
  retryStrategy: (attempt) => Math.min(2 ** attempt, 60),
};

const checkState = async () => {
  // Logic to check the state of the resource
  return { state: WaiterState.RETRY };
};

const waiter = createWaiter(waiterConfig, checkState);

waiter().then(() => console.log('Resource reached the desired state.')).catch((err) => console.error('Failed to reach the desired state:', err));

Other packages similar to @smithy/util-waiter

FAQs

Package last updated on 14 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc